/**
 * 
 */
package com.scaffold.commons.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringEscapeUtils;

import wangjg.security.interceptor.spring.MvcInterceptor;

/**
 * @author wangjg
 *
 */
public class PermissionInterceptor extends MvcInterceptor{
	
	protected void responseErr(HttpServletRequest request, HttpServletResponse response) throws IOException{
		String servletPath = request.getServletPath();
		if(servletPath.endsWith(".json")){
			response.setContentType("text/html");
			response.getWriter().print("{\"code\":\"403\",\"message\":\"权限不足!\"}");
		}else{
			String url = request.getContextPath()+servletPath;
			String qstr = request.getQueryString();
			if(qstr!=null && qstr.length()>0){
				url = url + '?' +qstr;
				url = StringEscapeUtils.escapeJavaScript(url);
			}
			response.sendRedirect(request.getContextPath()+"/authority/login.html?from="+url);
		}
	}
	
}
